ind<template>
  <base-layout
    dialog-title="x"
    :dialog-visible="dialogVisible"
    dialog-width="600px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel :show-add-button="false" :show-search-button="true" :showHandleBatchEdit="false"
                    :showExportDataButton="true" labelWidth="73" @search="search" @exportData="exportData" :left="true">
          <el-form-item label="供货名称:">
<!--            <el-input v-model="filters.username" style="width: 200px" placeholder="供货名称" clearable />-->
            <el-select v-model="filters.useruuid" placeholder="请选择供货商" clearable filterable >
              <el-option value="0" label="全部" >全部</el-option>
              <el-option
                v-for="item in users"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开始时间:">
            <el-date-picker type="date" placeholder="开始时间" format="yyyy-MM-dd" clearable v-model="filters.rechargetime" style="width: 100%;"></el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间:">
            <el-date-picker type="date" placeholder="结束时间" format="yyyy-MM-dd" clearable v-model="filters.endtime" style="width: 100%;"></el-date-picker>
          </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="false"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
        </template>
      </data-table>
    </template>

    <template #dialog>
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import util from '../../../utils/util'
import {findRechargeRecord,exportUpRechargeRecord} from '@/api/upapi'
import {findAllUpShopInfo} from '@/api/utilsapi'


export default {
  name: 'upAccountTurnover',
  mixins: [
    baseMixin({
      idName: 'id',
      findData:findRechargeRecord,
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      pageShow: true,
      dialogData:{},
      users:[],
      tableColumnAttributes: [
        { name: '供货名称', value: 'username' , formatter : this.userNameFormatter},
        { name: '充值金额', value: 'rechargeamount' },
        { name: '充值后余额', value: 'balance' },
        { name: '充值时间', value: 'rechargetime' },
        { name: '充值类型', value: 'payType' ,formatter : this.formatPayType},
        { name: '充值状态', value: 'rechargestatus' ,formatter : this.formatStatus},
        { name: '备注', value: 'remark' },
      ],
      filters: {
        username: '',
        rechargeamount:'',
        rechargetime:'',
        endtime:'',
        useruuid:''
      }
    }
  },
  methods: {
    async search(form){
      let para = {
        start: 0,
        pageSize: 10,
        starttime :  this.filters.rechargetime = (! this.filters.rechargetime || this.filters.rechargetime == '') ? '' : util.formatDate.format(new Date( this.filters.rechargetime), 'yyyy-MM-dd'),
        endtime: this.filters.endtime = (! this.filters.endtime || this.filters.endtime == '') ? '' : util.formatDate.format(new Date( this.filters.endtime), 'yyyy-MM-dd'),
        rechargeamount: this.filters.rechargeamount,
        username: this.filters.username,
        useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid
        ///{"start":0,"pageSize":10,"starttime":"","endtime":"","rechargeamount":"","username":"","useruuid":""}
      };
      this.searchOptions = para;
      this.setTableData()
    },
    async exportData(){
      let para = {
        start: this.start,
        pageSize:this.pageSize,
        starttime :  this.filters.rechargetime = (! this.filters.rechargetime || this.filters.rechargetime == '') ? '' : util.formatDate.format(new Date( this.filters.rechargetime), 'yyyy-MM-dd'),
        endtime: this.filters.endtime = (! this.filters.endtime || this.filters.endtime == '') ? '' : util.formatDate.format(new Date( this.filters.endtime), 'yyyy-MM-dd'),
        rechargeamount: this.filters.rechargeamount,
        username: this.filters.username,
        useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid
      };
      const result = await exportUpRechargeRecord(para);
      if(result && result.data){
        window.open(result.data.path);
      }
    },
    async findAllUserShopInfo(){
      let para = {useruuid:''};
      const result = await findAllUpShopInfo(para);
      this.users = result.data;
    },
    userNameFormatter(row){
      return row.user.username;
    },
    //状态转换
    formatStatus: function (row, column) {
      return row.rechargestatus ==  1 ? '充值成功' : row.sex == 0 ? '充值失败' : '未知';
    } ,
    formatPayType: function (row, column) {
      return row.payType ==  1 ? '充值' : row.payType == 2 ? '扣款' : '未知';
    } ,
  },
  mounted() {
    this.findAllUserShopInfo();
  }
}
</script>
